package com.jp.knowledge.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.HeadLineData;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;
import com.jp.knowledge.util.ImageLoadUtil;
import com.jp.knowledge.util.TimeUtil;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/3/29.
 */

public class BigDataItemAdapter extends RecycleVAdapter<HeadLineData> {

    public BigDataItemAdapter(Context context, @NonNull List<HeadLineData> list) {
        super(context, list);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_big_data;
    }

    @Override
    public void onBind(RecycleVHolder holder, int position) {
        HeadLineData headLineData = getData(position);

        ImageView icon = holder.get(R.id.icon);
        TextView title = holder.get(R.id.title);
        TextView desc = holder.get(R.id.descritption);
        TextView time = holder.get(R.id.time);

        if(headLineData.getIcon() != null && headLineData.getIcon().length() > 0)
//            ImageLoadUtil.load(context, headLineData.getIcon() + "?imageView2/2/w/100/interlace/1", icon);
            ImageLoadUtil.loadrund(mContext,
                    headLineData.getIcon() + "?imageView2/2/w/100/interlace/1",
                    icon, 20);
        else if(headLineData.getType() == 3)
            icon.setImageResource(R.mipmap.intelligent_analytics);
        else if(headLineData.getType() == 8)
            icon.setImageResource(R.mipmap.intelligent_analysis_products);
        else if(headLineData.getType() == 4)
            icon.setImageResource(R.mipmap.intelligent_analysis_character);
        else
            icon.setVisibility(View.GONE);

        setTextView(title, headLineData.getTitle());
        setTextView(desc, headLineData.getSource());
        setTextView(time, TimeUtil.friendly_time(headLineData.getCreatetime()));
        time.setVisibility(View.GONE);
    }

    private void setTextView(TextView textView, String str){
        if(str == null || str.trim().length() == 0) {
            textView.setVisibility(View.GONE);
        } else{
            textView.setText(str);
            textView.setVisibility(View.VISIBLE);
        }
    }
}
